/***********************************************************
 * $Id: Test.java 373 2013-01-22 14:25:55Z tkistel $
 * Created: 21.01.2013
 *
 * (c) 2013 Technische Hochschule Wildau
 * (University of Applied Sciences Wildau)
 * All rights reserved
 ***********************************************************/
package de.thwildau.tm.moses.internal.netty.channel.rxtx;

import gnu.io.CommPortIdentifier;

import java.io.IOException;
import java.util.Enumeration;

 

public class Test {

    /**
     * @param args
     * @throws BundleException 
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        
        NativeCodeInitialiser.initNativeLibDirectory();
        @SuppressWarnings("rawtypes")
        Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();
        while (portIdentifiers.hasMoreElements()) {
            CommPortIdentifier comport = (CommPortIdentifier)portIdentifiers.nextElement();
            System.out.println(comport.getName());
        }
//        Class<CommPortIdentifier> clazz = CommPortIdentifier.class;
//        ClassLoader cl = clazz.getClassLoader();
//        Enumeration<URL> resources = cl.getResources("META-INF/MANIFEST.MF");
//        URL url = null;
//        while (resources.hasMoreElements()) {
//            url = (URL)resources.nextElement();
//            if(url.getPath().contains("rxtx")) {
//                break;
//            }
//        }
//        System.out.println("URL: " + url);
//        InputStream urlStream = url.openStream();
////        InputStream stream = clazz.getResourceAsStream("/META-INF/MANIFEST.MF");
////        
//        Map<String, String> bundleManifest = ManifestElement.parseBundleManifest(urlStream, null);
//        for(Map.Entry<String, String> entry : bundleManifest.entrySet()) {
//            if(entry.getKey().equals("Bundle-NativeCode")) {
//                ManifestElement[] manifestElements = ManifestElement.parseHeader(entry.getKey(), entry.getValue());
//                
//            }
//        }

    }
    
//    private static NativeCodeSpecification createNativeCode(ManifestElement[] nativeCode) throws BundleException {
//        if (nativeCode == null)
//            return null;
//        NativeCodeSpecificationImpl result = new NativeCodeSpecificationImpl();
//        result.setName(Constants.BUNDLE_NATIVECODE);
//        int length = nativeCode.length;
//        if (length > 0 && nativeCode[length - 1].getValue().equals("*")) { //$NON-NLS-1$
//            result.setOptional(true);
//            length--;
//        }
//        NativeCodeDescriptionImpl[] suppliers = new NativeCodeDescriptionImpl[length];
//        for (int i = 0; i < length; i++) {
//            suppliers[i] = createNativeCodeDescription(nativeCode[i]);
//        }
//        result.setPossibleSuppliers(suppliers);
//        return result;
//    }
//
//    private static NativeCodeDescriptionImpl createNativeCodeDescription(ManifestElement manifestElement) throws BundleException {
//        NativeCodeDescriptionImpl result = new NativeCodeDescriptionImpl();
//        result.setName(Constants.BUNDLE_NATIVECODE);
//        result.setNativePaths(manifestElement.getValueComponents());
//        result.setOSNames(manifestElement.getAttributes(Constants.BUNDLE_NATIVECODE_OSNAME));
//        result.setProcessors(manifestElement.getAttributes(Constants.BUNDLE_NATIVECODE_PROCESSOR));
//        result.setOSVersions(createVersionRanges(manifestElement.getAttributes(Constants.BUNDLE_NATIVECODE_OSVERSION)));
//        result.setLanguages(manifestElement.getAttributes(Constants.BUNDLE_NATIVECODE_LANGUAGE));
//        try {
//            result.setFilter(manifestElement.getAttribute(Constants.SELECTION_FILTER_ATTRIBUTE));
//        } catch (InvalidSyntaxException e) {
//            String message = NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, Constants.BUNDLE_NATIVECODE, manifestElement.toString());
//            throw new BundleException(message + " : " + Constants.SELECTION_FILTER_ATTRIBUTE, BundleException.MANIFEST_ERROR, e); //$NON-NLS-1$
//        }
//        return result;
//    }

}
